﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;
using VisaCRM.Modules.Admin.Model;
using VisaCRM.Common.Helper;

namespace VisaCRM.Modules.Admin.Gateway
{
    class AccessLevelGateway
    {
        internal ObservableCollection<AccessLevel> GetAllAccessLevel()
        {
            ObservableCollection<AccessLevel> allAccessLevel = new ObservableCollection<AccessLevel>();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchAccessLevelList());
            if (dt.Rows.Count <= 0)
            {
                return allAccessLevel;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                allAccessLevel.Add(new AccessLevel()
                {
                    SecurityID = Convert.ToInt32(dataRow["Security_ID"].ToString()),
                    SecurityName = dataRow["Security_Name"].ToString()

                });
            }
            return allAccessLevel;
        }

        internal AccessLevel GetCurrentAccessLevel(int id)
        {
            AccessLevel accessLevel = new AccessLevel();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchCurrentAccessLevel(id));
            if (dt.Rows.Count <= 0)
            {
                return accessLevel;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                accessLevel.SecurityID = Convert.ToInt32(dataRow["Security_ID"].ToString());
                accessLevel.SecurityName = dataRow["Security_Name"].ToString();
            }
            return accessLevel;
        }
    }
}
